package com.behealthy.android;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.behealthy.util.Utility;
import com.example.behealthy.R;
import com.facebook.android.Facebook;
import com.facebook.android.LoginButton;
import com.facebook.android.SessionStore;

public class BeHealthyMainActivity extends Activity {

	// Facebook APP ID
			private static String App_ID = "474982679242477";

	// Instance of Facebook class
			private Facebook facebook;
			
	// Instance of shared preferences
			private final String PREFS = "MyPrefs";
			private SharedPreferences sharedPrefs;
		
	public void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState);
			 
		 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
			 
		 facebook = new Facebook(App_ID);
		 SessionStore.restore(facebook,this);
				 
		 sharedPrefs = getSharedPreferences(PREFS, 0);		 
		 boolean rememberMe = sharedPrefs.getBoolean("rememberMe", false);
				 
		 if(facebook.isSessionValid()) {
			 //The user is still logged in with the facebook account
					 Intent i = new Intent (getApplicationContext(), BeHealthyMenuActivity.class);
					 i.putExtra("session", true);
					 startActivity(i);
				 }
				 
			else if(rememberMe) {
				//The user saved his credentials
					 Intent i = new Intent (getApplicationContext(), BeHealthyLoginActivity.class);
					 startActivity(i);
				 }
				 
				else {
					//The user is logged out or has never used the application
					 	Intent i = new Intent (getApplicationContext(), BeHealthyRegisterActivity.class);
					 	startActivity(i);
				 }
			 
			
			 
		 }

           
}
